import { GeometryType, Pointer } from '@/graph/3d/config/shapes'
import * as THREE from 'three'
import { clone } from 'lodash'

let id = -1
const name = 'ABCDEFGHIJKJMNOPQRSTUVWXYZ'
export class PointerGenerator implements Pointer {
  id: string
  name: string
  type: GeometryType.Pointer
  canMove: boolean
  ref: THREE.Object3D<THREE.Object3DEventMap>[]
  activeted: boolean
  hovered: boolean
  direction: 0 | 1
  position: VerticesType
  offset: VerticesType
  constructor(options?: Partial<Pointer>, isReservedId = false) {
    if (!isReservedId) {
      id++
    }

    this.name = name[id % name.length]
    this.canMove = false
    this.ref = []
    this.activeted = false
    this.hovered = false
    this.direction = 0
    this.position = [0, 0, 0]
    this.offset = [0, 0, 0]

    if (options) {
      const _options = clone(options)
      // id内部生成，不可修改
      for (const key in _options) {
        if (Object.prototype.hasOwnProperty.call(_options, key)) {
          const element = _options[key]
          this[key] = element
        }
      }
    }

    const uuid = THREE.MathUtils.generateUUID()
    this.id = `pointer-${uuid}`
    this.type = GeometryType.Pointer
  }
  set(options: Partial<Pointer>) {
    Object.assign(this, options)
  }
  copy(options: Pointer) {
    this.set(clone(options))
  }
  clone(isReservedId = false) {
    return new PointerGenerator(this, isReservedId)
  }
}
